package edu.Test;

import java.util.Scanner;

public class test5 {
    public static int add(int[] scores) {
        int sum = 0;
        /*for (int i = 0; i < scores.length; i++) {
            int score = scores[i];
            sum += score;
        }*/
        for (int score : scores) {
            sum += score;
        }
        return sum;
    }

    //利用多参类型   ...   本质上属于数组  但是比数组灵活
    public static int add2(int... scores) {
        int sum = 0;
        for (int i : scores) {
            sum += i;
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println("你将要计算几个数的和：");
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int[] scores = new int[a];
        System.out.println("请依次输入数据：");
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请输入第"+(i+1)+"个数：");
            scores[i]=scan.nextInt();
        }
        int sum;
        System.out.printf("Method1.这"+a+"个数之和为：");
        System.out.println(add(scores));
        System.out.printf("Method2.这"+a+"个数之和为：");
        System.out.println(add2(scores));
    }
}